﻿using System;
using TrafficArchives.Client;
using TrafficArchives.Logs;
using TrafficArchives.Models;

namespace TrafficArchives.Archives
{
    /// <summary>
    /// 信誉档案单项查询。
    /// </summary>
    public partial class SimpleArchivesView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnQueryClicked(object sender, EventArgs e)
        {
            // 查询驾驶证信息。
            QueryDrivingLicence();

            // 查询交通违法情况。
            QueryIllegal();

            // 查询事故情况。
            QueryAccident();

            // 查询满分学习情况。
            QueryFullScoreStudyCase();

            // 查询未按时办理业务情况。
            QueryOverTimeBizCase();

            // 查询满12分未按时参加教育情况。
            QueryOverTimeEducate();

            // 查询其它(信誉档案)
            QueryArchives();

            var log = new LogInfo(LogType.信誉档案查询);
            LogWriter.Writer(log);
        }

        /// <summary>
        /// 查询驾驶证信息。
        /// </summary>
        private void QueryDrivingLicence()
        {
            var client = new ServiceClient();
            var data = client.GetDrivingLicence(TxtIdentityNo.Text, TxtArchivesNo.Text);
            TxtWebServiceMsg.Visible = data.WebServiceIsError;

            if (!data.WebServiceIsError && data.Rows.Count > 0)
            {
                var dataRow = data.Rows[0];
                LblName.Text = dataRow["xm"].ToString();
                LblSex.Text = dataRow["xb"].ToString();
                LblIdentityNo.Text = dataRow["sfzmhm"].ToString();
                LblBorthDay.Text = dataRow["csrq"].ToString();
                LblArchiveNo.Text = dataRow["dabh"].ToString();
                LblFirstLicensing.Text = dataRow["cclzrq"].ToString();
                LblCarType.Text = dataRow["zjcx"].ToString();
                LblDriverCardStatus.Text = dataRow["zt"].ToString();
                //LblManageOrgan.Text = dataRow[""].ToString(); // 管理部门
                LblLicensingOrgan.Text = dataRow["fzjg"].ToString(); // 发证机关
                LblAdminDivider.Text = dataRow["xzqh"].ToString();
            }
            else
            {
                LblName.Text = string.Empty;
                LblSex.Text = string.Empty;
                LblIdentityNo.Text = string.Empty;
                LblBorthDay.Text = string.Empty;
                LblArchiveNo.Text = string.Empty;
                LblFirstLicensing.Text = string.Empty;
                LblCarType.Text = string.Empty;
                LblDriverCardStatus.Text = string.Empty;
                LblManageOrgan.Text = string.Empty;
                LblLicensingOrgan.Text = string.Empty;
                LblAdminDivider.Text = string.Empty;
            }
        }

        /// <summary>
        /// 查询交通违法情况。
        /// </summary>
        private void QueryIllegal()
        {
            var client = new ServiceClient();
            var data = client.GetIllegalData(TxtIdentityNo.Text, TxtArchivesNo.Text);
            TxtWebServiceMsg.Visible = data.WebServiceIsError;
            if (!data.WebServiceIsError)
            {
                GridView01.DataSource = data;
                GridView01.DataBind();
            }
        }

        /// <summary>
        /// 查询事故情况。
        /// </summary>
        private void QueryAccident()
        {
            var client = new ServiceClient();
            var data = client.GetAccidentData(TxtIdentityNo.Text, TxtArchivesNo.Text);
            TxtWebServiceMsg.Visible = data.WebServiceIsError;
            if (!data.WebServiceIsError)
            {
                GridView02.DataSource = data;
                GridView02.DataBind();
            }
        }

        /// <summary>
        /// 查询满分学习情况
        /// </summary>
        private void QueryFullScoreStudyCase()
        {
            // GridView03
        }

        /// <summary>
        /// 查询未按时办理业务情况。
        /// </summary>
        private void QueryOverTimeBizCase()
        {
            // GridView04
        }

        private void QueryOverTimeEducate()
        {
            // GridView05
        }

        /// <summary>
        /// 查询其它(信誉档案)
        /// </summary>
        private void QueryArchives()
        {
            //GridView06
        }
    }
}